package com.bw.myapply_module.applycome

import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.SPUtils
import com.kf.common.mvi.viewmodel.BaseViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.launch

class ApplyComeViewModel : BaseViewModel<ApplyComeModel, ApplyComeState>() {
    override fun createState(): ApplyComeState {
        return ApplyComeState()
    }

    override fun createModel(): ApplyComeModel {
        return ApplyComeModel()
    }

    fun requestApplyCome(vistorId: Int) {
        var map = HashMap<String, Any>()
        map.put("time", System.currentTimeMillis())
        map.put("userId", SPUtils.getInstance().getInt("userId"))
        map.put("vistorId", vistorId)
        viewModelScope.launch(Dispatchers.IO) {
            mModel.requestApplyCome(map)
                .flowOn(Dispatchers.IO)
                .collect {
                    mutableContainer.updateUiState {
                        copy(comeEntity = it)
                    }
                }
        }
    }

}